class Solution {
public:
    int maxProfit(vector<int>& prices) {
        int a = prices[0], b = 0;
        for (int i = 1; i < prices.size(); ++i) {
            a = min(prices[i], a);
            b = max(b, prices[i] - a);
        }
        return b;
    }
};